package dz.common;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class SmallestPlay implements Comparable<SmallestPlay>{
	static List<SmallestPlay> list = new ArrayList<SmallestPlay>();
	static int indexFlag = 0;
	
	public SmallestPlay(){
		this.index = indexFlag++;
		this.height = 0;
		list.add(this);
	}
	
	
	int index;
	long height;
	
	
	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}

	public long getHeight() {
		return height;
	}

	public void setHeight(long height) {
		this.height = height;
	}

	public int compareTo(SmallestPlay arg0) {
        return (int)(this.getHeight() - arg0.getHeight());
    }
	
	public static void print(){
		System.out.println("---------");
		for(SmallestPlay u : list){
            System.out.println(u.getIndex() +  " = " + u.getHeight());
        }
	}
	
	
	public static void main(String[] args) {	
		new SmallestPlay();
		new SmallestPlay();
		new SmallestPlay();
		new SmallestPlay();
		
		SmallestPlay.getSmallestIndex();
		
		SmallestPlay.getSmallest().addHeight(1);
		SmallestPlay.print();
		SmallestPlay.getSmallest().addHeight(1);
		SmallestPlay.print();
		SmallestPlay.getSmallest().addHeight(1);
		SmallestPlay.print();
		SmallestPlay.getSmallest().addHeight(1);
		SmallestPlay.print();
		SmallestPlay.getSmallest().addHeight(1);
		SmallestPlay.print();
		SmallestPlay.getSmallest().addHeight(1);
		SmallestPlay.print();
	}

	private static int getSmallestIndex() {
		return getSmallest().getIndex();
	}

	public static SmallestPlay getSmallest() {
		return list.get(0);
	}

	public void addHeight(int i) {
		this.height += i;
		Collections.sort(list);
		print();
	}

	public static void init() {
		if(list.size() < 2){
			new SmallestPlay();
			new SmallestPlay();
			new SmallestPlay();
			
		}
		
	}

}

